package com.zhang.controller;

import com.zhang.entity.QuartzBody;
import com.zhang.entity.response.ResponseResult;
import com.zhang.entity.vo.AddQuartzBody;
import com.zhang.service.QuartzService;
import com.zhang.service.client.QuartzClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * User: 张
 * Date: 2024-11-28
 * Time: 10:20
 * Description:
 */
@RestController()
@RequestMapping("/job")
public class JobController {
    @Resource
    private QuartzClient quartzClient;
    @Autowired
    private QuartzService quartzService;

    @RequestMapping("/hello")
    public ResponseResult<Object> helloTest(){
        return ResponseResult.success(quartzClient.helloTest());
    }

    @PostMapping("/addJob")
    public ResponseResult<Object> addJob(@RequestBody AddQuartzBody addQuartzBody) throws Exception {
        quartzService.addJob(addQuartzBody);
        return ResponseResult.success();
    }

    @PutMapping("/updateJonCron")
    public ResponseResult<Object> updateJob(@RequestBody QuartzBody quartzBody){
        quartzService.updateJobCron(quartzBody);
        return ResponseResult.success();
    }

    @DeleteMapping("/deleteJob")
    public ResponseResult<Object> deleteJob(@RequestBody QuartzBody quartzBody){
        quartzService.deleteJob(quartzBody);
        return ResponseResult.success();
    }

    @PostMapping("/pauseJob")
    public ResponseResult<Object> pauseJob(@RequestBody QuartzBody quartzBody){
        quartzService.pauseJob(quartzBody);
        return ResponseResult.success();
    }

    @PostMapping("/resumeJob")
    public ResponseResult<Object> resumeJob(@RequestBody QuartzBody quartzBody){
        quartzService.resumeJob(quartzBody);
        return ResponseResult.success();
    }

    @PostMapping("/runAJobNow")
    public ResponseResult<Object> runAJobNow(@RequestBody QuartzBody quartzBody){
        quartzService.runAJobNow(quartzBody);
        return ResponseResult.success();
    }

    @GetMapping("/getAllJob")
    public ResponseResult<Object> getAllJob(@RequestParam("pageNum") Integer pageNum,
                                            @RequestParam("pageSize") Integer pageSize){
        return ResponseResult.success(quartzService.queryAllJobBean(pageNum,pageSize));
    }
    @GetMapping("/getAllRunningJob")
    public ResponseResult<Object> getAllRunningJob(@RequestParam("pageNum") Integer pageNum,
                                                   @RequestParam("pageSize") Integer pageSize){
        return ResponseResult.success(quartzService.queryRunJon(pageNum,pageSize));
    }
}
